import 'package:flutter/material.dart';
import 'package:flutter_trip/model/common_model.dart';

class SubNav2 extends StatelessWidget {
  const SubNav2({Key? key, required this.subNavList}) : super(key: key);

  final List<CommonModel> subNavList;

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(7)),
            color: Colors.white),
        child: Padding(
          padding: EdgeInsets.all(7),
          child: _items(context),
        ));
  }

  _items(BuildContext context) {
    int spec = (subNavList.length / 2 + 0.5).toInt();

    List<Widget> items = [];
    if (subNavList == null) return items;

    subNavList.forEach((element) {
      items.add(_item(context, element));
    });

    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: items.sublist(0, spec),
        ),
        Padding(padding: EdgeInsets.only(top: 10),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: items.sublist(spec, subNavList.length),
          ),
        )
      ],
    );
  }

  _item(BuildContext context, CommonModel element) {
    return Expanded(
        flex: 1,
        child: Column(
          children: [
            Image.network(
              element.icon!,
              width: 18,
              height: 18,
            ),
            Padding(
              padding: EdgeInsets.only(top: 7),
              child: Text(
                element.title!,
                style: TextStyle(fontSize: 13),
              ),
            )
          ],
        ));
  }
}
